package cn.codergege.demo.dev

import cn.codergege.demo.dao.PersonRepository
import cn.codergege.demo.entity.Person
import cn.codergege.demo.utils.toDate
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Profile
import org.springframework.stereotype.Component

@Component
@Profile("dev")
class DbInit {
    @Autowired
    lateinit var personRepository: PersonRepository
//    @Value("\${spring.profiles.active}")
//    lateinit var activeProfiles: String
//    @Value("\${spring.jpa.hibernate.ddl-auto}")
//    lateinit var ddlAuto: String

    fun initData() {
        println("DEV mode: Initialize database with test data...")
        // 给 Person 表添加数据
        val persons = listOf<Person>(
            Person(null, "AA", 1, "1986-05-29".toDate(), "AA@163.com"),
            Person(null, "BB", 0, null, "AA@163.com")
        )
        personRepository.saveAll(persons)
    }
}
